/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
private:
    int ans = 100000, pre = -100000;
    void in_order(TreeNode* root){
        if(!root)return;
        in_order(root->left);
        ans = min(ans, root->val - pre);
        pre = root->val;
        in_order(root->right);
    }
public:
    int minDiffInBST(TreeNode* root) {
        in_order(root);
        return ans;
    }
};
